nie.define("PageInit", function () {
    var img_list = __resload('img/preload');
    var pageIndex;
    var isIos = /iphone os/i.test(navigator.userAgent.toLowerCase()) || /ipad/i.test(navigator.userAgent.toLowerCase());
    var isAndroid = /android/i.test(navigator.userAgent.toLowerCase());
    var PAGE = function () {
        var fn = {
                setSwiper: function () {
                    var threeSp = new Swiper('#three-sp', {
                        followFinger: false,
                        speed: 500,
                        initialSlide: 0,
                        observeParents: true,
                        autoplay: 4000,
                        pagination: '.sp3 .swiper-pagination',
                        onSlideChangeStart: function (swiper) {
                        }
                    });
                    var fourSp = new Swiper('#four-sp', {
                        followFinger: false,
                        speed: 500,
                        initialSlide: 0,
                        observeParents: true,
                        autoplay: 4000,
                        pagination: '.sp4 .swiper-pagination',
                        onSlideChangeStart: function (swiper) {
                        }
                    });
                    var fiveSp = new Swiper('#five-sp', {
                        followFinger: false,
                        speed: 500,
                        initialSlide: 0,
                        observeParents: true,
                        autoplay: 4000,
                        pagination: '.sp5 .swiper-pagination',
                        onSlideChangeStart: function (swiper) {
                            $('.sp5 .arrowRight').hide();
                        },
                        onSlideChangeEnd: function (swiper) {
                            var index = swiper.realIndex;
                            if (index == 0) {
                                $('.sp5 .arrowRight').show();
                            }
                        }
                    });
                    var sevenSp = new Swiper('#seven-sp', {
                        followFinger: false,
                        speed: 500,
                        initialSlide: 0,
                        observeParents: true,
                        autoplay: 4000,
                        pagination: '.sp7 .swiper-pagination',
                        onSlideChangeStart: function (swiper) {
                        }
                    });
                    var mySwiper = new Swiper('#main-swiper', {
                        direction: 'vertical',
                        followFinger: false,
                        speed: 500,
                        initialSlide: 0,
                        nextButton: '.arrow',
                        observeParents: true,
                        preloadImages: false,
                        lazyLoading: true,
                        lazyLoadingInPrevNext: true,
                        lazyLoadingClass: 'lazy',
                        lazyLoadingInPrevNextAmount: 2,
                        onLazyImageLoad: function (swiper, slide, image) {
                            //console.log(swiper);//Swiper实例
                            //console.log(slide);//哪个slide里面的图片在加载
                            //console.log(image);//哪个图片在加载
                        }, onSlideChangeStart: function (swiper) {
                            var index = swiper.realIndex,
                                $tpa = $('.tpage');
                            $tpa.removeClass('flipFn');
                            threeSp.stopAutoplay();
                            fourSp.stopAutoplay();
                            fiveSp.stopAutoplay();
                            if (index == 3) {
                                threeSp.startAutoplay();
                            } else if (index == 4) {
                                fourSp.startAutoplay();
                            } else if (index == 5) {
                                fiveSp.startAutoplay();
                            } else if (index == 7) {
                                sevenSp.startAutoplay();
                            }

                            setTimeout(function () {
                                if (index >= 1 && index <= 8) {
                                    $tpa.addClass('flipFn');
                                    var className = "tnow" + index;
                                    var preClass = "tnow" + pageIndex;
                                    $(".t2016").removeClass("hide");
                                    $(".tpage").removeClass("hide");
                                    $(".tpage").removeClass(preClass);
                                    $(".tpage").addClass(className);
                                    pageIndex = index;
                                } else if (index > 8 && index < 11) {
                                    $(".t2016").removeClass("hide");
                                    $(".tpage").removeClass("hide");
                                    pageIndex = 8;
                                } else {
                                    $(".t2016").addClass("hide");
                                    $(".tpage").addClass("hide");
                                    pageIndex = index;
                                }
                            }, 50);

                            $("#main-swiper .swiper-wrapper .swiper-slide-active").addClass("active").siblings().removeClass("active");
                            $("#main-swiper .swiper-wrapper .swiper-slide-active").css('visibility', 'visible');
                        },
                        onSlideChangeEnd: function (swiper) {
                        }
                    });

                    setTimeout(function () {
                        threeSp.stopAutoplay();
                        fourSp.stopAutoplay();
                        fiveSp.stopAutoplay();
                        sevenSp.stopAutoplay();
                    }, 500);
                }
            },
            init = function () {
                fn.setSwiper();
            };
        return {
            fn: fn,
            init: init
        }
    }();

    Loader.show({
        iFileData: img_list,
        bgColor: '#000',//loading背景色值，默认#000
        mainWrap: '#main',//主题内容DOM，默认id值是Jmain
        defaultAnimation: true,//布尔值，默认值true。是否显示默认的loading动画
        customAnimation: function (curPer) {//加载进度回调函数，取值0~1
            // console.log(curPer);
        },
        completeCallback: function () {//完成预加载回调函数
            function isWeiXin() {
                var ua = window.navigator.userAgent.toLowerCase();
                if (ua.match(/MicroMessenger/i) == 'micromessenger') {
                    return true;
                } else {
                    return false;
                }
            }

            if (isWeiXin()) {
                audioAutoPlay();
            } else {
                $(".music").addClass("muClose");
            }
            $(".music").on("click", function () {
                if ($(this).hasClass("muClose")) {
                    // 处在暂停状态，点击播放
                    $("#au1")[0].play();
                    $(this).removeClass("muClose");
                } else {
                    // 点击暂停
                    $("#au1")[0].pause();
                    $(this).addClass("muClose");
                }
            });
            PAGE.init();
            //$('body').addClass('sbg');
            $('#main').css('opacity', '1');
            $(".sp0").addClass("active").siblings().removeClass("active");
        }
    });
});

function audioAutoPlay() {
    var audio = document.getElementById('au1'),
        play = function () {
            audio.play();
            document.removeEventListener("touchstart", play, false);
        };
    audio.play();
    document.addEventListener("touchstart", play, false);
}
